<?php


namespace app\common\controller;

use think\App;
use think\Controller;
use think\Db;
use think\facade\Cache;
use think\facade\Request;

class Basecontroller extends Controller
{
    const  OK = 666;
    const  MUST_LOGIN = 303;
    const  JUMP = 304;
    const  ERROR_URL = 405;
    const  NOPERMIS = 406;
    const  ERROR = 500;

    public function returnJson($code,$message,$data = null){
        $back = [
            'code'      =>  $code,
            'message'   =>  $message,
            'data'          =>  $data
        ];
        return json($back);
    }

    public function isExistence($phone){
        $result = Db::name('user')->where('phone','=',$phone)->find();
        if (!$result) return true;
        return false;
    }

    public function getUserID(){
        $token = Cache::get(Request::header('Authorization'));
        if (!$token) return false;
        return json_decode($token)->user_id;
    }

    public function getUserPhone(){
        $token = Cache::get(Request::header('Authorization'));
        if (!$token) return false;
        return json_decode($token)->phone;
    }
}